-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added pickup and drop actions #38
Added pickup and drop actions #38
Conversation
Codecov Report
@@ Coverage Diff @@
## master #38 +/- ##
==========================================
- Coverage 36.06% 32.83% -3.23%
==========================================
Files 13 13
Lines 305 335 +30
==========================================
Hits 110 110
- Misses 195 225 +30
Continue to review full report at Codecov.
|
src/objects.jl
Outdated
const GEM = Gem() | ||
Base.convert(::Type{Char}, ::Gem) = '♦' | ||
get_color(::Gem) = :magenta | ||
|
||
Base.@kwdef mutable struct Agent <: AbstractObject | ||
color::Symbol=:red | ||
dir::LRUD | ||
inv::Item=NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe create a new type of agent as you suggest in the related issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In implementing this, should I create an AbstractAgent <: AbstractObject
to simplify annotations for pickup functions and make additional agent types easier to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that'd be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in my last commit. I made some design decisions that I'm not confident were ideal, such as the way I made the constructor for Array_agent
, and my choice of Array_agent
as the name, but it works.
I am not confident that my implementation of traits is correct. I would appreciate if someone could look over my last commit and confirm that it's done correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most usages are correct! Well done!
My only concern is the name of Item
, though I also can not come up with a better name yet...
@findmyway @landrumb Sorry, I might be repeating something that might have been discussed earlier but I wanted to ask something. Why can't we use abstract objects to define traits such as Pickable = Union{Key, Gem} and check if Obj <: Pickable ?? |
Co-authored-by: Jun Tian <[email protected]>
Co-authored-by: Jun Tian <[email protected]>
Co-authored-by: Jun Tian <[email protected]>
@sriyash421 If I understand your question, what you're describing is essentially the same as what we do with traits, but the advantage of using traits is that you can more fluidly build it into the dispatch for functions that rely on the type annotation. However, I could be wrong as I've only known about traits for about 2 days. @findmyway can confirm or deny if that's the reason we're using traits, as he's more knowledgeable on the topic. |
Yes @landrumb is mostly right here. |
pickup
anddrop
functions were added in response to issue #36, aninv
attribute was added toAgent
, a new abstract classItem <: AbstractObject
was added to indicate objects that could be picked up, andKey
andGem
were changed to inherit from it.Outside of
objects.jl
,doorkey.jl
was changed to use the pickup function andinv
attribute ofAgent
, but its functionality is the same as before.As is, when an agent picks up or drops their inventory is up to the environment to decide. In
doorkey.jl
I left the existing behavior where walking over the key picks it up, but in an environment such as ObstructedMaze (#34) where items have to be dropped, there needs to be an interface besides walking over the object one wants to pick up. If the defaultNull
object was replaced withEmpty <: Item
, such that empty spaces could be picked up, it would allow picking up and dropping items by replacing theEmpty
object in the inventory with something else and vice versa, but this would not work with the automatic pickup used indoorkey.jl
, because the key would be automatically dropped on every forward movement.